{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# import relevant packages\n",
    "# pandas package is used to import data\n",
    "# statsmodels is used to inoke the functions that help in lm\n",
    "import pandas as pd\n",
    "import statsmodels.formula.api as smf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# import dataset\n",
    "data = pd.read_csv('D:/Pro ML book/linear_multi_reg_example.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:                 Weight   R-squared:                       0.982\n",
      "Model:                            OLS   Adj. R-squared:                  0.981\n",
      "Method:                 Least Squares   F-statistic:                     1095.\n",
      "Date:                Sat, 06 Jan 2018   Prob (F-statistic):           6.13e-19\n",
      "Time:                        12:37:13   Log-Likelihood:                 3.8748\n",
      "No. Observations:                  22   AIC:                            -3.750\n",
      "Df Residuals:                      20   BIC:                            -1.567\n",
      "Df Model:                           1                                         \n",
      "Covariance Type:            nonrobust                                         \n",
      "==============================================================================\n",
      "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      3.5355      0.085     41.654      0.000       3.358       3.713\n",
      "Age            0.4747      0.014     33.089      0.000       0.445       0.505\n",
      "==============================================================================\n",
      "Omnibus:                        0.648   Durbin-Watson:                   2.033\n",
      "Prob(Omnibus):                  0.723   Jarque-Bera (JB):                0.705\n",
      "Skew:                           0.321   Prob(JB):                        0.703\n",
      "Kurtosis:                       2.403   Cond. No.                         11.3\n",
      "==============================================================================\n",
      "\n",
      "Warnings:\n",
      "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n"
     ]
    }
   ],
   "source": [
    "# run regression\n",
    "est = smf.ols(formula='Weight~Age',data=data)\n",
    "est2=est.fit()\n",
    "print(est2.summary())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:                 Weight   R-squared:                       0.984\n",
      "Model:                            OLS   Adj. R-squared:                  0.982\n",
      "Method:                 Least Squares   F-statistic:                     585.7\n",
      "Date:                Sat, 06 Jan 2018   Prob (F-statistic):           8.49e-18\n",
      "Time:                        13:02:11   Log-Likelihood:                 5.1602\n",
      "No. Observations:                  22   AIC:                            -4.320\n",
      "Df Residuals:                      19   BIC:                            -1.047\n",
      "Df Model:                           2                                         \n",
      "Covariance Type:            nonrobust                                         \n",
      "==============================================================================\n",
      "                 coef    std err          t      P>|t|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      3.5842      0.088     40.700      0.000       3.400       3.769\n",
      "Age            0.4697      0.014     32.937      0.000       0.440       0.500\n",
      "New            0.1155      0.075      1.535      0.141      -0.042       0.273\n",
      "==============================================================================\n",
      "Omnibus:                        1.229   Durbin-Watson:                   2.434\n",
      "Prob(Omnibus):                  0.541   Jarque-Bera (JB):                0.415\n",
      "Skew:                           0.319   Prob(JB):                        0.813\n",
      "Kurtosis:                       3.213   Cond. No.                         13.2\n",
      "==============================================================================\n",
      "\n",
      "Warnings:\n",
      "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n"
     ]
    }
   ],
   "source": [
    "# run regression\n",
    "est = smf.ols(formula='Weight~Age+New',data=data)\n",
    "est2=est.fit()\n",
    "print(est2.summary())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
